package com.tancire.web.controller.works;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.works.domain.SideWork;
import com.tancire.works.service.ISideWorkService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 兼职管理Controller
 *
 * @author tancire
 * @date 2024-02-27
 */
@RestController
@RequestMapping("/works/sideWork")
public class SideWorkController extends BaseController {
    @Resource
    private ISideWorkService sideWorkService;

    /**
     * 查询兼职管理列表
     */
    @PreAuthorize("@ss.hasPermi('works:sideWork:list')")
    @GetMapping("/list")
    public TableDataInfo list(SideWork sideWork) {
        startPage();
        List<SideWork> list = sideWorkService.selectSideWorkList(sideWork);
        return getDataTable(list);
    }

    /**
     * 导出兼职管理列表
     */
    @PreAuthorize("@ss.hasPermi('works:sideWork:export')")
    @Log(title = "兼职管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SideWork sideWork) {
        List<SideWork> list = sideWorkService.selectSideWorkList(sideWork);
        ExcelUtil<SideWork> util = new ExcelUtil<SideWork>(SideWork.class);
        util.exportExcel(response, list, "兼职管理数据");
    }

    /**
     * 获取兼职管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('works:sideWork:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sideWorkService.selectSideWorkById(id));
    }

    /**
     * 新增兼职管理
     */
    @PreAuthorize("@ss.hasPermi('works:sideWork:add')")
    @Log(title = "兼职管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SideWork sideWork) {
        return toAjax(sideWorkService.insertSideWork(sideWork));
    }

    /**
     * 修改兼职管理
     */
    @PreAuthorize("@ss.hasPermi('works:sideWork:edit')")
    @Log(title = "兼职管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SideWork sideWork) {
        return toAjax(sideWorkService.updateSideWork(sideWork));
    }

    /**
     * 删除兼职管理
     */
    @PreAuthorize("@ss.hasPermi('works:sideWork:remove')")
    @Log(title = "兼职管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sideWorkService.deleteSideWorkByIds(ids));
    }
}
